<html>
<head><title>CS143 Project</title>
<body>
<h1>IMDB Database Search</h1>
<h3>By Timothy Woo and Daniel Pao</h3>
<p> Type an SQL query in the following box:</p>

<form action="query.php" method="GET">
<textarea name="query" cols="60" rows="8"></textarea>
</br>
<input type="submit" value="Submit"/>
</form>


<?php 
print "Your Results:";

$db_connection = mysql_connect("localhost", "cs143", "");
mysql_select_db("CS143", $db_connection);

$query = $_GET["query"];
if($_GET["query"]) {
	echo "$param";
}
$rs = mysql_query($query, $db_connection);

$numfields =  mysql_num_fields($rs);
print '<table border="1">';

for ($k=0;$k<$numfields;$k++) {
	$field_name = mysql_field_name($rs,$k);
	print "<td>"."$field_name"."</td>";
}

while($row = mysql_fetch_row($rs)){
	print '<tr>';
	for ($i=0;$i<$numfields;$i++) {
		if (is_null($row[$i]))
			print "<td>"."N/A"."</td>";
		else
			print "<td>"."$row[$i]"."</td>";
		
	}
	print '</tr>';
}
print '</table>';


mysql_close($db_connection);

?>

</body>
</html>
